package mystackgather;

class DoubleNode{
    int val;
//    DoubleNode next;
    DoubleNode prev;
    public DoubleNode(int val,DoubleNode prev){
        this.val =val;
        this.prev = prev;
    }
}

public class MyStackDoubleLinked {
//    DoubleNode head; 头节点 用不到
    DoubleNode tail;

    public void push(int x){
        if(tail == null){
            tail = new DoubleNode(x,tail);
        }else{
            DoubleNode node = new DoubleNode(x,tail);
//            tail.next = node;
            tail = node;
        }
    }

    public int pop(){
        if(isEmpty()){
            throw new RuntimeException(" 栈为空 ");
        }
        int oldVal = tail.val;
        tail = tail.prev;
        return oldVal;
    }
    public  boolean isEmpty(){
        return tail == null;
    }

    public int peek(){
        if(isEmpty()){
            throw new RuntimeException(" 栈为空 ");
        }
        return tail.val;
    }
}
